<!--海外管理-入库管理-->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />


    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e"
      :cell-class-name="cellClassMethod">


    </ex_super_table_page>

    <!-- <detail_overseas_inbound ref="detail_overseas_inbound" /> -->

    <taskAssign ref="ReceivingTaskAssign" :title="$tt('label_receiving_task_assign')"
      @afterSubmit="afterSubmitReceivingTask" multiple :intoTableOption="[
      { key: 'code', label: 'label_inbound_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'receivingOrderCode', label: 'label_order_code', 'min-width': 120, 'show-overflow-tooltip': true, },
      {
        type: 'operate', operate: [{
          label: 'title_task_assgin_record', click: (row) => this.$refs.dialogTaskDetailReceiving.show({
            title: `${this.$tt('label_inbound_code')}:${row.code}/${this.$tt('label_order_code')}:${row.receivingOrderCode}`,
            urlConfig: {
              url: '/wms-api/inbound/WmsInboundOverseasReceivingRpc/selectPage.json',
              data: { inboundOrderCode: row.code }
            }
          })
        }]
      }
    ]" />
    <detail_task_record ref="dialogTaskDetailReceiving" :tableModel="[
      { key: 'code', label: 'label_task_code' },
      { key: 'receivingUserName', label: 'label_receiving_task_user_name' },
      { key: 'receivingUserCode', label: 'label_receiving_task_user_code' },
      { key: 'receivingStatus', label: 'label_receiving_task_status', formatter: (r, c, v, i) => this.$enumShow(v, 'ReceivingTaskStatusEnum') },
    ]" />
    <taskAssign ref="PutawayTaskAssign" :title="$tt('label_putaway_task_assign')" @afterSubmit="afterSubmitPutawayTask"
      multiple :intoTableOption="[
      { key: 'code', label: 'label_inbound_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'receivingOrderCode', label: 'label_order_code', 'min-width': 120, 'show-overflow-tooltip': true, },
      {
        type: 'operate', operate: [{
          label: 'title_task_assgin_record', click: (row) => this.$refs.dialogTaskDetailPutaway.show({
            title: `${this.$tt('label_inbound_code')}:${row.code}/${this.$tt('label_order_code')}:${row.receivingOrderCode}`,
            urlConfig: {
              url: '/wms-api/inbound/WmsInboundOverseasPutawayRpc/selectPage.json',
              data: { inboundOrderCode: row.code }
            }
          })
        }]
      }
    ]" />

    <detail_task_record ref="dialogTaskDetailPutaway" :tableModel="[
      { key: 'code', label: 'label_task_code' },
      { key: 'putawayUserName', label: 'label_putaway_task_user_name' },
      { key: 'putawayUserCode', label: 'label_putaway_task_user_code' },
      { key: 'putawayStatus', label: 'label_putaway_task_status', formatter: (r, c, v, i) => this.$enumShow(v, 'PutawayTaskStatusEnum') },
    ]" />
    <overseas_quickReceiving ref="overseas_quickReceiving" @submitSuccess="submitQuickTackDeliveryAfter" :tableModel="[
      { key: 'code', label: 'label_inbound_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'customerCode', label: 'label_customer_info', 'width': 120, 'show-overflow-tooltip': true, },
      { key: 'expectBoxQty', label: 'label_plan_inbound_box_count', 'width': 100, },
      { key: 'expectSkuQty', label: 'label_plan_inbound_sku_count', 'width': 100, },
      { key: 'expectBoxQty', label: 'label_actual_inbound_box_count', 'width': 100, },
      { key: 'expectSkuQty', label: 'label_actual_inbound_sku_count', 'width': 100, },
    ]" orderKeyId="id" />

    <report_anomaly ref="report_anomaly" :orderTypeList="['INBOUND']" system="WMS" @afterSubmitSuccess="reload()" />



    <common_print_dialog ref="print_inbound_inventory"
      :title="$tt('label_print_any', { type: 'label_inbound_inventory', i18n: true })" :tableModel="[
      { key: 'code', label: 'label_inbound_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'receivingOrderCode', label: 'label_order_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'expectBoxQty', label: 'label_expected_box_number', 'width': 80, },
      { key: 'expectSkuQty', label: 'label_expected_sku_number', 'width': 80, },
    ]" printUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/printInboundList.json" :printHandler='(data, list) => {
      return {
        printList: list.map(it => {
          return {
            id: it.id,
            clientName: data.clientName,
            printerName: data.printerName,
            printCount: data.printNumSum,
          }
        })
      }
    }' previewUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/previewInboundList.json" :previewHandler='(data, row) => {
      data.id = row.id
      return data
    }' />

    <common_print_dialog ref="print_bebox_inventory"
      :title="$tt('label_print_any', { type: 'label_bebox_inventory', i18n: true })" :tableModel="[
      { key: 'code', label: 'label_inbound_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'receivingOrderCode', label: 'label_order_code', 'min-width': 140, 'show-overflow-tooltip': true, },
      { key: 'expectBoxQty', label: 'label_expected_box_number', 'width': 80, },
      { key: 'expectSkuQty', label: 'label_expected_sku_number', 'width': 80, },
    ]" printUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/printBoxList.json" :printHandler='(data, list) => {
      return {
        printList: list.map(it => {
          return {
            id: it.id,
            clientName: data.clientName,
            printerName: data.printerName,
            printCount: data.printNumSum,
          }
        })
      }
    }' previewUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/previewBoxList.json" :previewHandler='(data, row) => {
      data.id = row.id
      return data
    }' />

    <dialog_put_print ref="dialog_put_print" />

    <common_print_dialog ref="print_variance_receive" :title="$tt('label_generate_receipt_variance_report')"
      :tableVisiable="false" singlePrint :formDefualt='{
      receivingTime: new Date().getTime(), printNumSum: 1, principal: "艾姆勒海外仓储（深圳）有限责任公司", receivingParty: "诚实关税有限责任公司",
    }' :formModel='[{
      grid: [[{ key: "receivingTime", label: "label_receiving_day", type: "date-picker", },
      { key: "plateNumber", label: "label_tms_vehicle_license_number", attrs: { maxlength: 15, "show-word-limit": true }, },],
      [{ key: "principal", label: "label_principal_aspect", attrs: { maxlength: 30, "show-word-limit": true }, },
      { key: "receivingParty", label: "label_receive_aspect", attrs: { maxlength: 40, "show-word-limit": true }, },],
      [{ span: 12, col: { key: "contractNo", label: "label_srm_contract_management_contract_no", attrs: { maxlength: 40, "show-word-limit": true }, }, },],
      ]
    },
    ]' :formRules='{
      receivingTime: { required: true, type: "number", message: this.$tt("tip_can_no_empty"), label: "label_receiving_day" },
      plateNumber: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_tms_vehicle_license_number", },
      principal: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_principal_aspect", },
      receivingParty: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_receive_aspect", },
      contractNo: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_srm_contract_management_contract_no", },
    }' previewUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/previewReceivingVariance.json" :previewHandler="(data) => {
      const { params, ...other } = data
      return { ...other, ...params }
    }" printUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/printReceivingVariance.json" :printHandler="(data) => {
      const { clientId, fileType, printNumSum, printerName, params, ...other } = data
      if (params.codeList && _.isString(params.codeList)) {
        params.codeList = params.codeList ? params.codeList.split(',') : []
      } else {
        params.codeList = []
      }
      return {
        receivingVarianceParam: Object.assign({}, other, params),
        printList: [{ clientName: clientId, printerName: printerName, printCount: printNumSum, }],
      }
    }" />

    <common_print_dialog ref="print_variance_put" :title="$tt('label_generate_put_variance_report')"
      :tableVisiable="false" singlePrint :formDefualt='{
      receivingTime: new Date().getTime(), printNumSum: 1, principal: "艾姆勒海外仓储（深圳）有限责任公司", receivingParty: "诚实关税有限责任公司",
    }' :formModel='[{
      grid: [
        [{ key: "receivingTime", label: "label_receiving_day", type: "date-picker", },
        { key: "plateNumber", label: "label_tms_vehicle_license_number", attrs: { maxlength: 15, "show-word-limit": true }, },],
        [{ key: "principal", label: "label_principal_aspect", attrs: { maxlength: 30, "show-word-limit": true }, },
        { key: "receivingParty", label: "label_receive_aspect", attrs: { maxlength: 40, "show-word-limit": true }, },],
        [{ span: 12, col: { key: "contractNo", label: "label_srm_contract_management_contract_no", attrs: { maxlength: 40, "show-word-limit": true }, }, },],
      ]
    },]' :formRules='{
      receivingTime: { required: true,type: "number",  message: this.$tt("tip_can_no_empty"), label: "label_receiving_day" },
      plateNumber: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_tms_vehicle_license_number", },
      principal: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_principal_aspect", },
      receivingParty: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_receive_aspect", },
      contractNo: { required: true, message: this.$tt("tip_can_no_empty"), label: "label_srm_contract_management_contract_no", },
    }' previewUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/previewPutawayVariance.json" :previewHandler="(data) => {
      const { params, ...other } = data
      return { ...other, ...params }
    }" printUrl="/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/printPutawayVariance.json" :printHandler="(data) => {
      const { clientId, fileType, printNumSum, printerName, params, ...other } = data
      if (params.codeList && _.isString(params.codeList)) {
        params.codeList = params.codeList ? params.codeList.split(',') : []
      } else {
        params.codeList = []
      }
      return {
        putawayVarianceParam: Object.assign({}, other, params),
        printList: [{ clientName: clientId, printerName: printerName, printCount: printNumSum, }],
      }
    }" />

    <pack_box_dialog ref="pack_box_dialog" />
    <print_pre_box_generate ref="print_pre_box_generate" />
    <print_sku ref="print_sku" itemKey="skuId" />
    <print_box ref="print_box" />

    <!-- 导出 -->
    <dialog_export ref="exportRef" queryUrl="/wms-api/base/WmsExcelRpc/selectExportCellAttr.json" :queryParams="{
      exportType: 'WMS_INBOUND_ORDER_EXPORT'
    }" exportUrl='/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/export.json' :exportParams="exportParams"
      :searchModel="option.search.model" :searchData="searchData" />
  </div>
</template>

<script>
import print_sku from '@/component/print/print_sku'
import print_box from '@/component/print/print_box'
import print_pre_box_generate from '../../component/print/print_pre_box_generate.vue';
import pack_box_dialog from '../../component/pack_box_dialog.vue';

import business_function from "@/common/business_function"

import dialog_put_print from './dialog/dialog_put_print.vue'

import common_print_dialog from '@/component/print/common_print_dialog.vue';

import taskAssign from '@/component/wms/taskAssign.vue';
import detail_task_record from '@/component/dialog/detail_task_record.vue';

// import detail_overseas_inbound from './dialog/detail_overseas_inbound.vue';
import overseas_quickReceiving from './dialog/overseas_quickReceiving.vue';

import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';

import report_anomaly from '@/component/dialog/report_anomaly.vue'

import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'standard>inbound_manage'
export default {
  title: "title_standard_inbound_manager",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: {
    common_print_dialog, taskAssign, detail_task_record, print_sku, print_box, print_pre_box_generate,
    pack_box_dialog,
    overseas_quickReceiving,
    dialog_put_print, report_anomaly,
  },
  data() {
    return {
      selection: [],
      option: {
        search: {
          model: [
            { label: "label_inbound_code", key: "codeList", placeholder: 'tip_input_can_comma_separated' },
            { label: "label_order_code", key: "receivingOrderCode", },
            {
              label: "label_customer", key: "customerId", type: "common_customer_choose"
            },
            {
              label: "label_inbound_status", key: "statusList", type: 'select', enum: 'OverseasStatusEnum', multiple: true
            },
            { label: "label_inbound_type", key: "inboundType", type: 'select', enum: 'InboundTypeEnum' },
            { label: "label_delivery_type", key: "deliveryType", type: 'select', enum: 'DeliveryTypeEnum' },
            { label: "label_is_first_arrival", key: "isFirstArrival", type: 'select', enum: 'YesOrNoEnum', fold: true, },

            { label: "label_track_code", key: "trackingNumber", fold: true, },
            { label: "label_sku", key: "skuId", type: 'sku_selec_input', fold: true, },
            {
              label: "label_expected_arrival_date", key: 'startExpectedDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const limitKey = 'endExpectedDate'; const value = data[item.key]; const limitValue = data[limitKey];
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false } }}
                />)
              }

            },
            {
              label: "~", key: 'endExpectedDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const limitKey = 'startExpectedDate'; const value = data[item.key]; const limitValue = data[limitKey];
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false } }}
                />)
              }
            },
            {
              label: "label_create_time", key: 'startCreateDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'endCreateDate'
                const limitValue = data[limitKey]

                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false }
                  }}
                />)
              }

            },
            {
              label: "~", key: 'endCreateDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'startCreateDate'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false }
                  }}
                />)
              }
            },
            {
              label: "label_tms_complete_date", key: 'startFinishDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'endFinishDate'
                const limitValue = data[limitKey]

                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false }
                  }}
                />)
              }

            },
            {
              label: "~", key: 'endFinishDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'startFinishDate'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false }
                  }}
                />)
              }
            },
          ],
        },
        actionExtra: [
          { label: 'label_export', attrs: { type: "primary" }, click: this.exportFn },
          {
            label: 'label_batch_print', type: "more",
            list: [
              {
                label: 'label_print_sku_barcode',
                click: () => {
                  this.printSkuTag(this.selection)
                },
              },
              {
                label: 'label_print_box_tag',
                click: () => {
                  this.printBoxTag(this.selection)
                },
              },

              {
                label: { _key: 'label_print_any', type: 'label_inbound_inventory', i18n: true },
                click: () => {
                  if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))
                  this.$refs.print_inbound_inventory.show(this.selection)
                }
              },
              {
                label: { _key: 'label_print_any', type: 'label_bebox_inventory', i18n: true },
                click: () => {
                  if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))
                  this.$refs.print_bebox_inventory.show(this.selection)

                }
              },
            ]
          },
          {
            label: 'label_sku_pack_box',
            click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))
              if (this.selection.length > 1) return this.$message.error(this.$tt('tip_only_select_single_order'))
              const item = _.head(this.selection)
              if (item.boxIsEmpty != 'Y') {
                return this.$message.error(this.$tt('tip_no_need_packbox'))
              }
              if (item.acceptanceStatus != 'ACCEPTANCE_COMPLETED') {
                return this.$message.error(this.$tt('tip_place_first_acceptance'))
              }
              if (item.packingBoxStatus == 'PACKING_BOX_COMPLETED') {
                return this.$message.error(this.$tt('tip_has_operate_finish'))
              }
              this.$refs.pack_box_dialog.show({ order: item })
            },
          },
          {
            label: "label_generate_receipt_variance_report", auth: "wms_overseas_generate_receipt_variance_report",
            click: () => {
              business_function.confirmOperateBaseSelectOrForm.call(this, {
                data: this.$refs.SuperTablePage.getSearchFormData(),
                model: this.option.search.model,
                selection: this.selection,
                callback: (selection, data) => {
                  let params = {}
                  if (!_.isEmpty(selection)) {
                    params = {
                      codeList: selection.map(it => it.code)
                    }
                  } else {
                    params = data
                  }
                  this.$refs.print_variance_receive.show([], {
                    default: {
                      params
                    },
                  });
                }
              })

            },
          },
          {
            label: "label_generate_put_variance_report", auth: "wms_overseas_generate_put_variance_report",
            click: () => {
              business_function.confirmOperateBaseSelectOrForm.call(this, {
                data: this.$refs.SuperTablePage.getSearchFormData(),
                model: this.option.search.model,
                selection: this.selection,
                callback: (selection, data) => {
                  let params = {}
                  if (!_.isEmpty(selection)) {
                    params = {
                      codeList: selection.map(it => it.code)
                    }
                  } else {
                    params = data
                  }
                  this.$refs.print_variance_put.show([], {
                    default: {
                      params
                    },
                  });
                }
              })
            },
          },
          { label: 'label_receiving_task_assign', attrs: { type: "primary" }, auth: 'wms_overseas_receive_task_assign', click: this.clickReceivingTask },
          { label: 'label_putaway_task_assign', attrs: { type: "primary" }, auth: 'wms_overseas_put_task_assign', click: this.clickPutawayTask },
          // { label: 'label_quick_checkin', attrs: { type: "primary" }, click: this.clickQuickReceiving },
          // { label: 'label_print_inbound_code', attrs: { type: "primary" }, click: this.$noFunction },
          // { label: 'label_packing_box_inventory', click: this.$noFunction },
          // {
          //   label: { _key: 'label_print_any', type: 'label_inbound_inventory', i18n: true }, click: () => {
          //     if (_.isEmpty(this.selection)) return this.$message.error(this.$tt("tip_please_select_order"))
          //     this.$refs.print_InboundList.show(this.selection)
          //   }
          // },
          // {
          //   label: { _key: 'label_print_any', type: 'label_bebox_inventory', i18n: true }, click: () => {
          //     if (_.isEmpty(this.selection)) return this.$message.error(this.$tt("tip_please_select_order"))
          //     this.$refs.print_BoxList.show(this.selection)
          //   }
          // },

          // { label: 'label_export', attrs: { type: "danger" }, click: this.$noFunction },
        ],
        table: {
          url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/selectPage.json",
          model: this.init_table_model(),

        }
        ,

      },
      exportParams: '',
      searchData: []

    };
  },
  computed: {

  },

  mounted() {
  },
  props: {

  },

  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            ...this.$defaultDescAttrs,
            model: [],
          },
        },

        {
          key: 'customerName', label: 'label_customer_info', 'min-width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$formatNameCode(v, r.customerCode)
        },
        { key: 'inboundType', label: 'label_inbound_type', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v) => this.$enumShow(v, "InboundTypeEnum") },
        { key: 'deliveryType', label: 'label_delivery_type', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v) => this.$enumShow(v, "DeliveryTypeEnum") },


        { key: 'code', label: 'label_inbound_code', 'min-width': 160, },
        { key: 'receivingOrderCode', label: 'label_order_code', 'min-width': 150, },
        { key: 'bizType', label: 'label_business_type', 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "BizTypeEnum") },

        { key: 'expectBoxQty', label: 'label_expected_box_number', 'width': 80, },
        { key: 'expectSkuQty', label: 'label_expected_sku_number', 'width': 80, },
        { key: 'receivingBoxQty', label: 'label_receiving_box_number', 'width': 80, },
        { key: 'receivingSkuQty', label: 'label_receiving_number', 'width': 80, },

        { key: 'packingBoxBoxQty', label: 'label_packingBox_box_number', 'width': 80, },
        { key: 'packingBoxSkuQty', label: 'label_packingBox_number', 'width': 80, },

        { key: 'putawayBoxQty', label: 'label_putaway_box_number', 'width': 80, },
        { key: 'putawaySkuQty', label: 'label_putaway_number', 'width': 80, },


        { key: 'status', label: 'label_inbound_status', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "OverseasStatusEnum") },

        {
          key: 'receivingUserName', label: 'label_receiving_user', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v) => this.$formatNameCode(v, r.receivingUserCode)
        },
        {
          key: 'putawayUserName', label: 'label_putaway_user', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v) => this.$formatNameCode(v, r.putawayUserCode)
        },
        {
          key: 'isAutomaticWarehouseArea', label: 'label_is_auto_location', 'width': 110, 'show-overflow-tooltip': true,
          render: (h, { row, column }) => this.$renderText(h, row[column.property], { enum: "YesOrNoEnum" })
        },
        {
          key: 'boxDetailIsEmpty', label: 'label_require_sku_detail_manage', 'width': 120,
          render: (h, { row, column }) => {
            const v = row[column.property]
            return (<div class={v == 'Y' ? 'color_danger' : 'color_success'}>{this.$enumShow(v, "YesOrNoOppositeEnum")}</div>)
          }

        },
        {
          key: 'boxIsEmpty', label: 'label_is_box_code_manage', 'width': 120,
          render: (h, { row, column }) => {
            const v = row[column.property]
            return (<div class={v == 'Y' ? 'color_danger' : 'color_success'}>{this.$enumShow(v, "YesOrNoOppositeEnum")}</div>)
          }
        },

        // { key: 'supplyName', label: 'label_logistics_supplier', 'min-width': 120, 'show-overflow-tooltip': true, },
        // {
        //   key: 'productName', label: 'label_logistics', 'min-width': 120, 'show-overflow-tooltip': true,
        //   formatter: (r, c, v) => this.$formatNameCode(v, r.productCode)
        // },
        // { key: 'trackingNumber', label: 'label_track_code', 'min-width': 120, 'show-overflow-tooltip': true, },
        // { key: 'platformCode', label: 'label_platform_no', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v) => this.$enumShow(v, "PlatformCodeEnum") },

        {
          type: 'operate', width: 180, fixed: "right", operate: [
            {
              label: "label_edit",
              if: (row) => row.isWarehouseEdit == 'Y',
              disabled: (row) => !['WAIT_INBOUND'].some(e => e == row.status),
              click: (row) => this.clickEditReceipt(row)

            },
            {
              label: "label_delete", type: 'confirm-button', buttonClass: "button_text_danger", confirmButtonType: 'danger',
              if: (row) => row.isWarehouseEdit == 'Y',
              disabled: (row) => !['WAIT_INBOUND'].some(e => e == row.status),
              url: '/oms-api/receiving/InboundReceivingRpc/delete.json', message: 'text_confirm_sure_delete',
              params: (v) => { return { code: v.code } }, done: ['reload', 'tip']

            },
            {
              type: 'more',
              items: [
                { label: 'label_view_detail', click: (row) => { this.clickDetail(row) } },
                {
                  label: 'label_receiving', auth: '/page/wms/overseas/inbound/receiving',
                  click: (row) => { this.gotoReceiving(row) }
                },
                { label: 'label_putaway', auth: '/page/wms/overseas/inbound/putaway', click: (row) => { this.gotoPutaway(row) } },
                {
                  label: 'label_acceptance', auth: '/page/wms/overseas/inbound/check',
                  click: (row) => { this.gotoCheck(row) }
                },

                {
                  label: 'label_print_sku_barcode', click: (row) => this.printSkuTag([row]),
                },
                {
                  label: 'label_print_box_tag', click: (row) => this.printBoxTag([row]),
                },
                {
                  label: { _key: 'label_print_any', type: 'label_inbound_inventory', i18n: true }, click: (row) => {
                    // this.$refs.print_InboundList.show([row])
                    this.$refs.print_inbound_inventory.show([row], { single: true })

                  }
                },
                {
                  label: { _key: 'label_print_any', type: 'label_bebox_inventory', i18n: true }, click: (row) => {
                    this.$refs.print_bebox_inventory.show([row], { single: true })
                  }
                },
                {
                  label: { _key: 'label_print_any', type: 'label_put_inventory', i18n: true }, click: (row) => {
                    this.$refs.dialog_put_print.show(row)
                  }
                },
                {
                  label: 'label_sku_pack_box',
                  disabled: (row) => !["ACCEPTANCE_COMPLETED"].includes(row.acceptanceStatus) && ["PACKING_BOX_COMPLETED"].includes(row.packingBoxStatus),
                  click: (row) => {
                    const item = row
                    this.$refs.pack_box_dialog.show({ order: item })
                  },
                },

                {
                  label: 'label_sku_pack_box_confirm',
                  disabled: (row) => !["PARTIAL_PACKING_BOX"].includes(row.packingBoxStatus),
                  click: (row) => this.packboxConfirm(row)
                },

                // { label: 'label_download_attachment', click: this.$noFunction },

                { label: 'label_report_exception', click: (row) => this.reportAnomaly(row), },

                {
                  label: 'label_receiving_confirm', auth: 'wms_overseas_receiving_confirm',
                  disabled: row => row.receivingSkuQty <= 0 || row.receivingStatus != 'PARTIAL_RECEIVING',
                  click: (row) => this.receivingConfirm(row)
                },
                {
                  label: 'label_putaway_confirm', auth: 'wms_overseas_put_confirm',
                  disabled: row => row.putawaySkuQty <= 0 || row.putawayStatus != 'PARTIAL_PUTAWAY',
                  click: (row) => this.putawayConfirm(row)
                },
                {
                  label: 'label_acceptance_confirm', auth: 'wms_overseas_acceptance_confirm',
                  disabled: row => row.receivingStatus != 'RECEIVING_COMPLETED' || row.acceptanceStatus == 'ACCEPTANCE_COMPLETED',
                  click: (row) => this.acceptanceConfirm(row)
                },
                {
                  label: 'label_reset_receiving', auth: 'wms_overseas_reset_receiving',
                  disabled: (row) => row.receivingStatus == 'NOT_RECEIVING' || row.putawayStatus != 'NOT_PUTAWAY',
                  click: (row) => this.resetReceiving(row)
                },
              ]
            }
          ]
        }
      ]
    },
    printSkuTag(rows) {
      if (_.isEmpty(rows)) return this.$message.error(this.$tt('tip_please_select_order'))
      this.$ajax({
        url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/selectBatchDetail.json",
        method: 'post', loading: true,
        data: { ids: rows.map(it => it.id) },
        success: (res) => {
          if (res && res.data && res.data.rows) {
            this.$confirm(this.$tt('tip_is_confirm_print_inbound_order_sku_count'), this.$tt('label_tip'), {
              type: 'warning'
            }).then(() => {
              const list = _.flatMap(res.data.rows, it => !_.isEmpty(it.inboundOrderSkuList) ? it.inboundOrderSkuList : it.detailList)
              const uq = _.uniqBy(list, it => it.skuId).map(it => {
                const num = _.reduce(list.filter(item => item.skuId == it.skuId), (r, v) => this.$math_add(r, (v.quantity)), 0)
                this.$set(it, 'printNum', num)
                return it
              })
              this.$refs.print_sku.show(uq)
            }).catch((action) => {
              if (action === 'cancel') {
                const list = _.flatMap(res.data.rows, it => !_.isEmpty(it.inboundOrderSkuList) ? it.inboundOrderSkuList : it.detailList)
                const uq = _.uniqBy(list, it => it.skuId)
                this.$refs.print_sku.show(uq)
              }
            });

          }
        }
      })
    },
    printBoxTag(rows) {
      if (_.isEmpty(rows)) return this.$message.error(this.$tt('tip_please_select_order'))
      const list = _.uniqBy(rows, it => (it.boxIsEmpty == 'Y' && it.packingBoxStatus != "PACKING_BOX_COMPLETED") || it.boxDetailIsEmpty == 'Y')
      if (list.length >= 2) {
        return this.$message.error(this.$tt('tip_has_box_code_no_with_no_box_code_inbound_order_print'))
      }
      if (list.some(it => (it.boxIsEmpty == 'Y' && it.packingBoxStatus != "PACKING_BOX_COMPLETED") || it.boxDetailIsEmpty == 'Y')) {
        if (_.uniqBy(rows, it => it.customerId).length >= 2) {
          return this.$message.error(this.$tt('tip_customer_different'))
        }
        this.$refs.print_pre_box_generate.show({
          list: rows,
          generateUrl: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/generateBatchBoxNo.json",
          code: _.head(rows).code
        })

      } else {
        this.$ajax({
          url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/selectBatchDetail.json",
          method: 'post', loading: true,
          data: { ids: rows.map(it => it.id) },
          success: (res) => {
            if (res && res.data && res.data.rows) {
              const reslist = _.flatMap(res.data.rows, it => it.detailList)

              const boxNo_group = _.groupBy(reslist, it => it.boxId)
              const printData = []
              _.forOwn(boxNo_group, (value, k) => {
                const order = _.find(res.data.rows, it => it.code == _.head(value).inboundOrderCode)
                printData.push(
                  {
                    orderId: order ? order.id : "",
                    boxId: k,
                    binNo: _.head(value).boxNo,
                    targetWarehouse: order ? order.destinationWarehouseName : "",
                    customerCode: order ? order.customerCode : "",
                    skuCategoryNum: _.uniqBy(value, sku => sku.skuId).length,
                    skuCount: _.reduce(value, (r, v) => this.$math_add(r, (v.quantity)), 0),

                  }
                )
              })
              this.$refs.print_box.show(printData)
            }
          }
        })
      }
    },
    reportAnomaly(row) {
      this['$refs']['report_anomaly'].showNew({
        data: {
          customerName: row.customerName,
          customerCode: row.customerCode,
          customerId: row.customerId,
          orderNo: row.code,
          orderType: 'INBOUND',
        },
        formDisabled: true,
        onlySetData: true,
      })
    },
    cellClassMethod({ row, column, rowIndex, columnIndex }) {
      if (column.property == 'status') {
        if (['WAIT_RECEIVING', 'WAIT_PUTAWAY'].some(it => it == row.status)) {
          return 'color_primary'
        } else if (['PARTIAL_RECEIVING', 'PARTIAL_PUTAWAY'].some(it => it == row.status)) {
          return 'color_warning'
        } else if (row.status == 'INBOUND') {
          return 'color_success'
        }
      }
      return ""
    },
    clickAddReceipt() {
      this.$router.push({ path: '/page/oms/order/inbound/order_operate', query: { wms: true, emitKey } })
    },
    clickEditReceipt(row) {
      this.$router.push({ path: '/page/oms/order/inbound/order_operate', query: { code: row.code, wms: true, emitKey } })
    },
    gotoCheck(row) {
      this.$router.push({ name: '/page/wms/overseas/inbound/check', params: { 'inboundOrderCode': row.code } })
    },
    gotoReceiving(row) {
      this.$router.push({ name: '/page/wms/overseas/inbound/receiving', params: { 'inboundOrderCode': row.code } })
    },
    gotoPutaway(row) {
      this.$router.push({ name: '/page/wms/overseas/inbound/putaway', params: { inboundOrderCode: row.code } })
    },
    clickDetail(row) {
      // let title = `${this.$tt('label_inbound_code')}：${row.code}`
      // this.$refs['detail_overseas_inbound'].show({ params: { id: row.id }, title })
      this.$router.push({ name: '/page/wms/overseas/inbound/inbound_detail', query: { 'id': row.id } })

    },

    //任务分配
    clickReceivingTask(e) {
      let list = this.selection;
      if (list.length <= 0) {
        this.$message.error(this.$tt("tip_noSelect_receiving_list"))
        return
      }
      this.$refs['ReceivingTaskAssign'].show(this.$loginUser.currentWarehouseId, list)
    },

    afterSubmitReceivingTask({ select, list }) {

      let taskList = []
      list.map(it => {
        select.map(people => {
          taskList.push({
            inboundOrderId: it.id,
            receivingUserId: people.userId,
            receivingUserCode: people.userCode,
            receivingUserName: people.userName,
          })
        })
      })
      this.$ajax({
        url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/assigningReceivingTask.json",
        method: 'post', type: 'json',
        data: { taskList },
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.reload()
          this.$refs['ReceivingTaskAssign'].hide()
          this.$emitPage('overseas=>receiving_task', 'reload')
        }
      })
    },
    clickPutawayTask() {
      let list = this.selection;
      if (list.length <= 0) {
        this.$message.error(this.$tt("tip_noSelect_receiving_list"))
        return
      }
      this.$refs['PutawayTaskAssign'].show(this.$loginUser.currentWarehouseId, list)
    },
    afterSubmitPutawayTask({ select, list }) {
      let taskList = []
      list.map(it => {
        select.map(people => {
          taskList.push({
            inboundOrderId: it.id,
            putawayUserId: people.userId,
            putawayUserCode: people.userCode,
            putawayUserName: people.userName,
          })
        })
      })
      this.$ajax({
        url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/assigningPutawayTask.json",
        method: 'post', type: 'json',
        data: { taskList },
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.reload()
          this.$refs['PutawayTaskAssign'].hide()
          this.$emitPage('overseas=>putaway_task', 'reload')
        }
      })
    },
    receivingConfirm(row) {

      this.$confirm(this.$tt('text_is_sure_receiving_confirm'), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/receivingConfirm.json",
          method: 'post', type: 'json',
          data: { inboundOrderId: row.id },
          success: (res) => {
            this.$message.success(this.$tt('tip_submit_success'))
            this.reload()
          }
        })
      }).catch(() => {
      });
    },
    packboxConfirm(row) {
      this.$confirm(this.$tt('text_is_sure_packbox_confirm'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/wms-api/inbound/WmsInboundTransitPackagingRpc/packingBoxConfirm.json",
          method: 'post', type: 'json',
          data: { id: row.id },
          success: (res) => {
            this.$message.success(this.$tt('tip_submit_success'))
            this.reload()
          }
        })
      }).catch(() => {
      });
    },
    putawayConfirm(row) {

      this.$confirm(this.$tt('text_is_sure_putaway_confirm'), this.$tt('label_tip'), {

        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/putawayConfirm.json",
          method: 'post', type: 'json',
          data: { inboundOrderId: row.id },
          success: (res) => {
            this.$message.success(this.$tt('tip_submit_success'))
            this.reload()
          }
        })
      }).catch(() => {
      });
    },
    resetReceiving(row) {
      this.$confirm(this.$tt('text_is_sure_reset_receiving'), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/resetReceiving.json",
          method: 'post', type: 'json',
          data: { inboundOrderId: row.id },
          success: (res) => {
            this.$message.success(this.$tt('tip_submit_success'))
            this.reload()
            this.$emitPage('overseas=>receiving_task', 'reload')
          }
        })
      }).catch(() => {
      });
    },

    acceptanceConfirm(row) {
      this.$confirm(this.$tt('text_is_sure_acceptance_confirm'), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/acceptanceConfirm.json",
          method: 'post', type: 'json',
          data: { inboundOrderId: row.id },
          success: (res) => {
            this.$message.success(this.$tt('tip_submit_success'))
            this.reload()
          }
        })
      }).catch(() => {
      });

    },
    clickQuickReceiving() {

      let _list = this.getSelection();
      if (_list.length <= 0) {
        return this.$message.error(this.$tt("tip_noSelect_receiving_list"))
      }

      this.$refs.overseas_quickReceiving.show({
        tableList: _.cloneDeep(_list)
      })
    },
    submitQuickTackDeliveryAfter() {
      this.reload()
    },
    exportFn() {
      this.exportParams = {
        ...this.$refs.SuperTablePage.getSearchFormData(),
        idList: this.selection.map(it => it.id)
      }
      this.searchData = this.$refs.SuperTablePage.getSearchFormData()

      // business_function.confirmOperateBaseSelectOrForm.call(this, {
      //           data: this.$refs.SuperTablePage.getSearchData(),
      //           model: this.option.search.model,
      //           selection: this.selection,
      //         })
      this.$refs.exportRef.show()
    }
  }
};

</script>
<style></style>
